#include <pthread.h>

#define TEXT_SIZE 256  /* = PAGE_SIZE, size of each message */
#define TEXT_NUM 10   /* maximal number of mesages */
    /* total size can not exceed current shmmax,
       or an 'invalid argument' error occurs when shmget */

/* a demo structure, modified as needed */
struct shared_struct { //like student name
    int flag; //0 -- null , 1 -- being used, 2 -- deleted
    char name[TEXT_SIZE]; /* buffer for message reading and writing */
    int id; /* buffer for message reading and writing */
    struct shared_struct* next;
};

#define PERM S_IRUSR|S_IWUSR|IPC_CREAT

#define ERR_EXIT(m) \
    do { \
        perror(m); \
        exit(EXIT_FAILURE); \
    } while(0)


struct shared_struct* list_find_index(int index, struct shared_struct* head, int size);

int exchage_nodes(struct shared_struct* node1, struct shared_struct* node2);

int shiftUp(struct shared_struct* child, int child_index, int size, struct shared_struct* head);

int shiftDown(struct shared_struct* par, int par_index, int size, struct shared_struct* head);

int pop(struct shared_struct* head,  int size, int* count);

int insert(struct shared_struct* head, int* count, int size, char* name, int id);

int removeAtIndex(struct shared_struct* head, int size, int index, int* count);

int replace(struct shared_struct * head, int size, int index, char * name, int id);

struct shared_struct* searchList(struct shared_struct* head ,int size , int id, int * count);

void printList(struct shared_struct* head, int size);

